package ercahshu

func isSymmetric(root *TreeNode) bool {
	var dfs func(n1, n2 *TreeNode) bool
	dfs = func(n1, n2 *TreeNode) bool {
		if n1 == nil && n2 == nil {
			return true
		} else if (n1 == nil && n2 != nil) || (n1 != nil && n2 == nil) || n1.Val != n2.Val {
			return false
		}
		return dfs(n1.Left, n2.Right) && dfs(n1.Right, n2.Left)
	}
	return dfs(root.Left, root.Right)
}
